package com.example.redis;

import io.micrometer.core.instrument.util.TimeUtils;
import jodd.time.TimeUtil;
import lombok.extern.log4j.Log4j2;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author: 扎马斯
 * @date: 2024年08月30日 16:39
 * @describe:
 */
@RestController
@RequestMapping("/redis")
@Log4j2
public class RedisTest {
    @Autowired
    private RedissonClient redissonClient;

    @PostMapping("/test")
    public void testRedisson(@RequestParam("key") String key) {
        RLock lock = redissonClient.getLock(key);
        try {
            lock.lock();
            Thread.sleep(10000);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            lock.unlock();
        }
        log.info("已经解锁了-----------------------");
    }

}
